package com.lrd.shardingjdbc.controller;

import com.lrd.shardingjdbc.entity.User;
import com.lrd.shardingjdbc.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

/**
 * @author LRD
 * @create 2021-03-24 23:17
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/save")
    public String insert(){
        User user = new User();
        user.setNickName("Lv"+new Random().nextInt());
        user.setPassWord("123456");
        user.setSex(1);
        user.setBirthday("1996-05-09");
        userMapper.addUser(user);
        return "success";
    }
    @GetMapping("listUser")
    public List<User> listUser(){
        return userMapper.findAllUsers();
    }
}

